//
//  IFlyIVWConfig.m
//  AIKITDemo
//
//  Created by xyzhang on 2023/3/8.
//

#import "IFlyIVWConfig.h"
#import "Definition.h"
NSString * const IFlyWakeup_words_default = @"你好小迪"; // 默认唤醒词
NSString * const IFlyWakeup_words_multiple = @"你好小迪,大白大白,hello 小迪,hi 小团子"; //多唤醒词

@implementation IFlyIVWConfig

+ (IFlyIVWConfig *)sharedInstance {
    static IFlyIVWConfig  *instance = nil;
    static dispatch_once_t predict;
    dispatch_once(&predict, ^{
        instance = [[IFlyIVWConfig alloc] init];
    });
    return instance;
}

- (id)init {
    self = [super init];
    
    if(self) {
        [self defaultSetting];
        return  self;
    }
    return nil;
}

-(void)defaultSetting {
    
    _abilityId = AIKIT_ABILITYID_IVW;
    _gramLoad = @"1";
    _threshold = @"900";//@"0 0:900"
    
//    _wakeupWords = IFlyWakeup_words_default;
    _wakeupWords = IFlyWakeup_words_multiple;
    _wakeupWordsLockedFlag = NO;
    
    _sampleRate = @"16000";
    _timeoutInterval = AIKIT_TIMEOUT_VALUE;
    _audioSource = IFLY_AUDIO_SOURCE_MIC;
    
}

//
//
//
//
//

/* 获取多唤醒词门限值
 * 门限值就是唤醒得分 如果你设置了这个门限值是1000 那么你唤醒得分如果超过这个1000的话 是不会被唤醒的
 * 0 1:100 => 0 为第一个唤麗词文件 1为第二个唤醒词 100 为门限值，多个唤麗词情况下用 | 分割，如: '0 0:100|0 1:200’
 * demo这里就一个唤醒词文件，所以第一个参数为0,为了方便测试，所以唤醒词的门限值为一致的，
 * 开发者可以根据业务需要设置不同的门限值
 */
- (NSString *)getMultipleThresholdString {
    
    _wakeupWords = [_wakeupWords stringByReplacingOccurrencesOfString:@"，" withString:@","];
    NSArray *wakeupWords = [_wakeupWords componentsSeparatedByString:@","];
    if (wakeupWords.count==0) {
        return @"";
    }
    
    NSString *thresholdStr = @"";
    for (int i=0; i<wakeupWords.count; i++) {
        [IFlyDebugLog showLog:@"%@", wakeupWords[i]];
        thresholdStr = [thresholdStr stringByAppendingFormat:@"0 %i:%@", i, _threshold];
        if (i != wakeupWords.count-1) {
            thresholdStr = [thresholdStr stringByAppendingFormat:@"|"];
        }
    }
    // 0 0:900|0 1:900|0 2:900|0 3:900
    [IFlyDebugLog showLog:@"thresholdStr:%@", thresholdStr];
    return thresholdStr;
}

@end
